#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

#include "ForwardList.h"

namespace UnitTestForwardList
{		
	TEST_CLASS(UnitTestForwardList)
	{
	public:
		
		TEST_METHOD(TestEmpty)
		{
			ForwardList<int> fli;
			Assert::AreEqual(true, fli.is_empty());

		}

		TEST_METHOD(TestPushFront)
		{
			ForwardList<int> fli;
			Assert::AreEqual(true, fli.is_empty());

			int x = 10;
			fli.push_front(x);
			Assert::AreEqual(10, fli.front());
			x = 20; fli.push_front(x);
			Assert::AreEqual(20, fli.front());
			x = 30; fli.push_front(x);
			Assert::AreEqual(30, fli.front());
			x = 40; fli.push_front(x);
			Assert::AreEqual(40, fli.front());
		}

		TEST_METHOD(TestRemove)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			fli.remove(20);
			fli.remove(10);
			fli.remove(0);

			int i = 90;
			for (auto it = fli.begin(); it != fli.end(); it++)
			{
				Assert::AreEqual(i, it->value);
				i -= 10;
			}


		}

		TEST_METHOD(TestSort)
		{
			ForwardList<int> fli;

			int a = 1;
			int b = 2;
			int c = 3;
			int d = 4;
			fli.push_front(c);
			fli.push_front(a);
			fli.push_front(d);
			fli.push_front(b);

			fli.sort();

			Assert::AreEqual(a, fli.front());
			Assert::AreEqual(d, fli.back());


		}

		TEST_METHOD(TestIteratorBeginEnd)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			int i = 90;
			for (auto it = fli.begin(); it != fli.end(); it++)
			{
				Assert::AreEqual(i, it->value);
				i -= 10;
			}

		}

		TEST_METHOD(TestAccessFirst)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			Assert::AreEqual(90, fli.front());
		}

		TEST_METHOD(TestPopFront)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			fli.pop_front();

			Assert::AreEqual(80, fli.front());

			ForwardList<int> fli2;
			fli2.push_front(20);
			fli2.pop_front();
			Assert::AreEqual(true, fli2.is_empty());



		}

		TEST_METHOD(TestClear)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			fli.clear();

			Assert::AreEqual(true, fli.is_empty());
		}


		TEST_METHOD(TestInsertAfter)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			fli.insert_after(50);

			Assert::AreEqual(50, fli.back());


		}


		TEST_METHOD(TestEraseAfter)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			fli.erase_after();
			Assert::AreEqual(10, fli.back());


			ForwardList<int> fli2;
			fli2.push_front(10);
			fli2.erase_after();
			Assert::AreEqual(true, fli2.is_empty());


		}

		TEST_METHOD(TestCopyConstructor)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			ForwardList<int> fli2 (fli); 

			int i = 90;
			for (auto it = fli2.begin(); it != fli2.end(); it++)
			{
				Assert::AreEqual(i, it->value);
				i -= 10;
			}

		}

		TEST_METHOD(TestCopyAssignmentOperator)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			ForwardList<int> fli2;
			for (int i = 0; i <= 100; i += 20)
			{
				fli2.push_front(i);
			}

			fli2 = fli;

			int j = 90;
			for (auto it = fli2.begin(); it != fli2.end(); it++)
			{
				Assert::AreEqual(j, it->value);
				j -= 10;
			}

			ForwardList<int> fli3;

			fli = fli3;

			Assert::AreEqual(true, fli3.is_empty());

		}

		TEST_METHOD(TestSwap)
		{
			ForwardList<int> fli;
			for (int i = 0; i < 100; i += 10)
			{
				fli.push_front(i);
			}

			ForwardList<int> fli2;
			for (int i = 0; i <= 100; i += 20)
			{
				fli2.push_front(i);
			}

			fli.swap(fli2);


			int i = 100;
			for (auto it = fli.begin(); it != fli.end(); it++)
			{
				Assert::AreEqual(i, it->value);
				i -= 20;
			}

			int j = 90;
			for (auto it = fli2.begin(); it != fli2.end(); it++)
			{
				Assert::AreEqual(j, it->value);
				j -= 10;
			}

		}
		

	};
}